package com.woniu.job.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author sunnylausong
 * 真，过滤登录
 * 2019/12/30
 * 12:07
 */
@WebFilter("/user")
public class UserLoginFilter implements Filter {


    @Override
    public void init(FilterConfig filterConfig) throws ServletException
    {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
    {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse rep = (HttpServletResponse) response;
        String url = req.getRequestURL().toString();
        if(url.contains("/user/register")||url.contains("/user/login")||url.contains("/user/logout")){
            chain.doFilter(request,response);
        }
        else {
            rep.sendRedirect("/jsp/personal/user_login.jsp");
        }
    }

    @Override
    public void destroy()
    {

    }
}
